package com.yaorange.certificate.service.impl;

import java.util.Collections;
import java.util.List;
import java.util.Map;

import com.yaorange.certificate.domain.NjtArea;
import com.yaorange.certificate.domain.NjtUnitConfig;
import com.yaorange.certificate.mapper.NjtAreaMapper;
import com.yaorange.certificate.mapper.NjtUnitConfigMapper;
import com.yaorange.certificate.vo.NjtCountVo;
import com.yaorange.common.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.yaorange.certificate.mapper.NjtCertificateCountMapper;
import com.yaorange.certificate.domain.NjtCertificateCount;
import com.yaorange.certificate.service.INjtCertificateCountService;
import org.springframework.transaction.annotation.Transactional;

/**
 * 合格证统计数据Service业务层处理
 *
 * @author coach tam
 * @date 2024-07-17
 */
@Service
public class NjtCertificateCountServiceImpl implements INjtCertificateCountService
{
    @Autowired
    private NjtCertificateCountMapper njtCertificateCountMapper;
    @Autowired
    private NjtUnitConfigMapper njtUnitConfigMapper;
    @Autowired
    private NjtAreaMapper njtAreaMapper;

    /**
     * 查询合格证统计数据
     *
     * @param id 合格证统计数据主键
     * @return 合格证统计数据
     */
    @Override
    public NjtCertificateCount selectNjtCertificateCountById(Long id)
    {
        return njtCertificateCountMapper.selectNjtCertificateCountById(id);
    }

    /**
     * 查询合格证统计数据列表
     *
     * @param njtCertificateCount 合格证统计数据
     * @return 合格证统计数据
     */
    @Override
    public List<NjtCertificateCount> selectNjtCertificateCountList(NjtCertificateCount njtCertificateCount)
    {
        return njtCertificateCountMapper.selectNjtCertificateCountList(njtCertificateCount);
    }

    /**
     * 新增合格证统计数据
     *
     * @param njtCertificateCount 合格证统计数据
     * @return 结果
     */
    @Override
    public int insertNjtCertificateCount(NjtCertificateCount njtCertificateCount)
    {
        njtCertificateCount.setCreateTime(DateUtils.getNowDate());
        return njtCertificateCountMapper.insertNjtCertificateCount(njtCertificateCount);
    }

    /**
     * 修改合格证统计数据
     *
     * @param njtCertificateCount 合格证统计数据
     * @return 结果
     */
    @Override
    public int updateNjtCertificateCount(NjtCertificateCount njtCertificateCount)
    {
        njtCertificateCount.setUpdateTime(DateUtils.getNowDate());
        return njtCertificateCountMapper.updateNjtCertificateCount(njtCertificateCount);
    }

    /**
     * 批量删除合格证统计数据
     *
     * @param ids 需要删除的合格证统计数据主键
     * @return 结果
     */
    @Override
    public int deleteNjtCertificateCountByIds(Long[] ids)
    {
        return njtCertificateCountMapper.deleteNjtCertificateCountByIds(ids);
    }

    /**
     * 删除合格证统计数据信息
     *
     * @param id 合格证统计数据主键
     * @return 结果
     */
    @Override
    public int deleteNjtCertificateCountById(Long id)
    {
        return njtCertificateCountMapper.deleteNjtCertificateCountById(id);
    }
    /**
     * 获取本表中所有年份
     *
     * @return 本表中所有年份集合
     */
    @Override
    public List<String> getYearList() {
        return njtCertificateCountMapper.selectYearList();
    }

    @Override
    @Transactional(readOnly = true)
    public List<NjtCountVo> getPrintCountList(Integer unitId, String year) {
        NjtUnitConfig njtUnitConfig = njtUnitConfigMapper.selectNjtUnitConfigById(Long.valueOf(unitId));
        NjtCertificateCount njtCertificateCount = new NjtCertificateCount();
        njtCertificateCount.setProvince(njtUnitConfig.getProvince());
        njtCertificateCount.setCity(njtUnitConfig.getCity());
        njtCertificateCount.setArea(njtUnitConfig.getArea());
        return njtCertificateCountMapper.selectPrintCountList(njtCertificateCount,year);
    }

    @Override
    @Transactional(readOnly = true)
    public List<Map<String, Object>> streetStatisticsByArea(String yearStr, Long unitId) {

        NjtUnitConfig njtUnitConfig = njtUnitConfigMapper.selectNjtUnitConfigById(Long.valueOf(unitId));
        return njtCertificateCountMapper.selectStreetStatisticsByArea(njtUnitConfig);
    }
}
